import { Query } from '../../Hooks/useQuery'
import { Point } from '../../utils/es6PutPoint'
export const useGetEvent = () => {
  const putShow = ref(true)
  const eventStatus = ref()
  const eventData = ref([])
  const featureId = ref([])
  var service = {
    name: 'guanggu',
    layerId: 2
  }
  const getData = async () => {
    eventData.value = []
    await Query.queryByLayer({
      service,
      callback: (res) => {
        res.forEach((item) => {
          const mergedObj = { ...item.values_.values_, id: item.id_ }
          eventData.value.push(mergedObj)
        })
      }
    })
    nextTick() // 等待更新视图
    return eventData
  }

  let docLayer, attr
  const handlePutStatus = async (row, eventStatus, map) => {
    let featureIds = row.id
    docLayer = map.getLayers().item(1)
    attr = [{ type: 'smallint', key: '处理状态', value: eventStatus }]
    Point.put({
      featureIds,
      eventStatus,
      service,
      attr,
      docLayer
    })
    await getData()
  }
  onMounted(async () => {
    await getData()
  })

  return { eventData, featureId, putShow, eventStatus, getData, handlePutStatus }
}
